/*===== Appendix Table 1: Sensitivity to demographics & poverty cutoff ========*/

cap program drop creategr
program define creategr
cap drop strecdums2
cap drop recdums2
recode year 2008=1 2009=2 2010=3 nonmissing=0, g(recdums2)
egen strecdums2 = group(recdums2 state_fips)
end 


local  dem i.race##i.post2002 i.marst i.famsize i.nchild i.educ i.hispan##i.post2002 i.sex i.nchild##i.pre1988  i.race#i.pre1988
*local  dem i.dem_race##i.post2002  i.dem_race#i.pre1988 i.dem_married i.dem_famsize ///
*i.dem_nchild i.dem_nchild##i.pre1988 i.dem_educ i.dem_female i.dem_hisp##i.post2002

local rhs1 age* unemprate statepcgdp stateeitcrate
local rhs2 age* unemprate statepcgdp stateeitcrate
local rhs4 age* hpi ur_high_edu wage_high_edu eitc tanf4 snap4 ACA

local a1 year i.state_fips `dem'
local a2 year i.state_fips `dem' strecdums2  c.year##i.state_fips i.year#i.division
local  a4 year i.state_fips `dem'

local primary

local j .5
local thresholdlist .5  1 1.5 2 3 4
local thresholdlist 1
local d 1
local j 1
local spec 4



/* OUR PREFERRED CONTROLS  */
use  "${data1}march_regready_1984.dta", clear
gen eitc_raw = eitc
gen byte demgroup_lowskill = demgroup26==1 & inrange(age, 16,24) 
gen byte demgroup_workingage = inrange(age, 16, 64)
gen byte demgroup_children = age<16
ren (demgroup0 demgroup_workingage demgroup27  demgroup_lowskill demgroup21 demgroup24  demgroup_children) ///
(demgroup2 demgroup3 demgroup4 demgroup5 demgroup6 demgroup7 demgroup8)
gen lead = lnMWF1


foreach j of numlist `thresholdlist' {
foreach spec of numlist 3 {
foreach d of numlist 1(1)8 {
local q = `j' * 100
  if `j' < 4 {
	  cap drop under
	  if `spec'==4 gen under = contpov2 < `j'
	  else gen under = contpov < `j'
	  
	  replace eitc = eitc_raw*eitc_ref
	  di "Poverty threshold `q'"
	  
	  if `spec'==4 replace lnMWF1=0
	  else replace lnMWF1=lead
	  
	  if `d' == 5 reg under lnMW   `rhs`spec'' `a`spec''  [pw=wtsupp] if demgroup`d'==1,  cluster(state_fips)
	  else reghdfe under lnMW `rhs`spec''  [pw=wtsupp] if demgroup`d'==1 , a(`a`spec'') cluster(state_fips)
	  est save "${est}ster/dube/MW1_`q'_dem`d'_s`spec'_dube", replace

	  if `d' == 5 reg under lnMWF1 lnMW lnMWL1 lnMWL2 lnMWL3  `rhs`spec'' `a`spec''  [pw=wtsupp] if demgroup`d'==1,  cluster(state_fips)
	  else reghdfe under lnMWF1 lnMW lnMWL1 lnMWL2 lnMWL3 `rhs`spec''  [pw=wtsupp] if demgroup`d'==1 , a(`a`spec'') cluster(state_fips)
	  est save "${est}ster/dube/MW2_`q'_dem`d'_s`spec'_dube", replace
		* di `spec'
	  }
  else {
	  if `d' == 5 reg contpov lnMW   `rhs`spec'' `a`spec''  [pw=wtsupp] if demgroup`d'==1,  cluster(state_fips)
	  else reghdfe contpov lnMW `rhs`spec''  [pw=wtsupp] if demgroup`d'==1 , a(`a`spec'') cluster(state_fips)
	  est save "${est}ster/dube/MW1_`q'_dem`d'_s`spec'_dube", replace

	  if `d' == 5 reg contpov lnMWF1 lnMW lnMWL1 lnMWL2 lnMWL3  `rhs`spec'' `a`spec''  [pw=wtsupp] if demgroup`d'==1,  cluster(state_fips)
	  else reghdfe contpov lnMWF1 lnMW lnMWL1 lnMWL2 lnMWL3 `rhs`spec''  [pw=wtsupp] if demgroup`d'==1 , a(`a`spec'') cluster(state_fips)
	  est save "${est}ster/dube/MW2_`q'_dem`d'_s`spec'_dube", replace
		* di `spec'
	  }
  }

}
}




